﻿
<!--
https://github.com/netnr
https://gitee.com/netnr
https://www.netnr.com
https://zme.ink
-->


<!DOCTYPE html>
<html>
<head>

    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <link rel='shortcut icon' href='/favicon.ico' type='image/x-icon' />


    <title>留言 脚本服务</title>

    <meta name="keywords" content="netnr NET牛人 留言" />
    <meta name="description" content="Script Services 匿名留言" />

</head>
<body>
<div id='LoadingMask' style='position:fixed;top:0;left:0;bottom:0;right:0;background-color:white;z-index:19999;background-image:url('/images/loading.svg');background-repeat:no-repeat;background-position:48% 45%'></div>
<link href='https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css' rel='stylesheet'>
<link href='https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css' rel='stylesheet'>
<script src='https://cdn.jsdelivr.net/npm/jquery@3.5.0/dist/jquery.min.js'></script>
<script src='https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js'></script>
<script src='https://cdn.jsdelivr.net/npm/jzjs@2.0.2/2.0.2/jz.min.js'></script>
<link href='https://cdn.jsdelivr.net/npm/netnrnav@1.1.0/src/netnrnav.css' rel='stylesheet' />
<script src='https://cdn.jsdelivr.net/npm/netnrnav@1.1.0/src/netnrnav.js' defer async></script>

<script>
    $.ajax({
        url: '/images/icon.svg?20201228',
        dataType: 'text',
        success: function (data) {
            $('body').append('<div class="d-none">' + data + '</div>')
        }
    })
</script>

        <link href="/css/global.css?v=YuzFOH_Z7ma5bs-3HMdZQu0aPQZ1pkBqrzQ_Ri8Yh3k" rel="stylesheet" />
        <script src="/js/global.js?v=ckkNo3hER74SKnNCuouMgEfxEpEMP3phtPl9uA0_Lnc"></script>
            <!--导航-->
            <button type="button" class="MenuToggle show-in-mobile btn btn-primary ml-3 mt-3">
                <span class="fa fa-align-justify fa-2x"></span>
            </button>
            <div class="netnrnav horizontal">
                <div class="netnrnav-wrapper">
                    <ul>
                        <li><a href="https://www.netnr.com" class="siteIcon"><img src="/favicon.svg" /> 首页</a></li>
                        <li><a href="https://www.netnr.com/gist/discover" title="代码片段"><span class="fa fa-fw fa-file-code-o"></span> Gist</a></li>
                        <li><a href="https://www.netnr.com/run/discover" title="在线运行代码"><span class="fa fa-fw fa-play"></span> Run</a></li>
                        <li><a href="https://www.netnr.com/doc" title="文档管理"><span class="fa fa-fw fa-book"></span> Doc</a></li>
                        <li><a href="https://www.netnr.com/draw/discover" title="绘制"><span class="fa fa-fw fa-paint-brush"></span> Draw</a></li>
                        <li><a href="/" title="ss.js.org"><span class="fa fa-fw fa-wrench"></span> 服务</a></li>
                        <li style="background-image: radial-gradient(ellipse, white, rgb(227, 248, 240))">
                            <!--标题-->
                                <a href='javascript:location.reload(false)' title="匿名留言">
                                    <svg class="titleicon"><use xlink:href="#message"></use></svg> &#x7559;&#x8A00;
                                </a>
                        </li>
                        <li>
                            <a class="text-muted"><span class="fa fa-fw fa-ellipsis-h"></span></a>
                            <ul>
                                <li><a target="_blank" title="码云" href="https://gitee.com/netnr"><i class="fa fa-fw fa-git"></i> Gitee <sup><i class="fa small fa-external-link"></i></sup></a></li>
                                <li><a target="_blank" title="GitHub" href="https://github.com/netnr"><i class="fa fa-fw fa-github"></i> GitHub <sup><i class="fa small fa-external-link"></i></sup></a></li>
                            </ul>
                        </li>
                    </ul>
                </div>
            </div>
        <div class="min300 mt-3">
            <style>
    .messagebox img {
        width: 32px;
    }

    .messagebox textarea {
        height: 90px;
    }

    .messagebox pre {
        white-space: pre-wrap;
        word-break: break-word;
    }
</style>
<div class="container-fluid">
    <div class="row messagebox">
        <div class="col-md-12">
            <ul class="list-unstyled" id="messagelist"></ul>
        </div>
        <div class="col-md-12 my-3">
            <form id="form1">
                <div class="input-group mb-3">
                    <div class="input-group-prepend">
                        <span class="input-group-text">昵称</span>
                    </div>
                    <input class="form-control" placeholder="输入昵称（可选）" name="UserNickname" maxlength="50">
                </div>
                <div class="input-group mb-3">
                    <div class="input-group-prepend">
                        <span class="input-group-text">内容</span>
                    </div>
                    <textarea class="form-control" name="Content" placeholder=" 内容：写留言内容，文明点 ^_^ &#xD;&#xA; 支持 Markdown &#xD;&#xA; 快捷提交：Ctrl + Enter"></textarea>
                </div>
            </form>
            <button class="btn btn-warning" id="btnSave">留言</button>
        </div>
    </div>
</div>

<script src='https://cdn.jsdelivr.net/gh/netnr/cdn/libs/bmob/1.7.0/bmob.min.js?170'></script>
<link href='https://cdn.jsdelivr.net/npm/netnrmd@2.6.0/src/netnrmd.css' rel='stylesheet' />
<script src='https://cdn.jsdelivr.net/npm/netnrmd@2.6.0/src/netnrmd.bundle.js'></script>


<script>
    ss.bmobInit();
    var mg = {
        page: 1,
        pageNumber: 999,
        bquery: Bmob.Query("NetnrMessage"),
        messageObjectSave: function () { return new mg.MessageObject() },
        list: function () {
            ss.loading();
            var query = mg.bquery;
            query.limit(mg.pageNumber);
            query.skip((mg.page - 1) * mg.pageNumber);
            query.find().then(res => {
                ss.loading(0);
                var htm = [];
                $(res).each(function (i) {
                    var id = 'mi' + (i + 1);
                    htm.push('<li class="media mb-3 border-bottom" id="' + id + '">');
                    htm.push('<a class="mr-3" href="#' + id + '"><img src="/images/photo.svg"></a>');
                    var nickname = ss.htmlEncode(this.UserNickname == "" ? "guest" : this.UserNickname);
                    htm.push('<div class="media-body"><h6 class="mt-0 mb-2 text-info">' + nickname + '<small class="mx-3 text-muted">' + this.createdAt + '</small><a class="text-warning" href="#' + id + '">#' + (i + 1) + '</a></h6>');
                    if (this.IsBlock) {
                        htm.push('<em class="badge badge-secondary" title="该信息已被屏蔽">block</em>');
                    } else {
                        var vc = netnrmd.render(this.Content);
                        vc = vc.replace(/@\S+/g, function (n) {
                            return '<span class="text-info">' + n + '</span>'
                        }).replace(/#\d+/g, function (n) {
                            return '<a href="' + n.replace("#", "#mi") + '" class="text-warning">' + n + '</a>'
                        });
                        htm.push('<div>' + vc + '</div>');
                    }
                    htm.push('</div></li>');
                });
                if (htm.length) {
                    $('#messagelist').html(htm.join(''));
                } else {
                    $('#messagelist').html('no message');
                }
            }).catch(err => {
                jz.alert("查询失败");
                console.log(err);
                ss.loading(0);
            })
        }
    }

    mg.list();
    $('textarea[name="Content"]').keydown(function (e) {
        e = e || window.event;
        var keys = e.keyCode || e.which || e.charCode;
        if (keys == 13 && e.ctrlKey) {
            $('#btnSave')[0].click();
        }
    });
    $('#btnSave').click(function () {
        var un = $('input[name="UserNickname"]'), uc = $('textarea[name="Content"]'), objv = {};
        objv.UserNickname = un.val().trim();
        objv.Content = uc.val().substring(0, 9999);
        if (objv.Content == "") {
            jz.msg("请输入内容")
        } else {
            var query = mg.bquery;
            for (var i in objv) {
                query.set(i, objv[i]);
            }
            query.save().then(res => {
                jz.msg("操作成功");
                uc.val('');
                mg.list();
                ss.ls["nickname"] = objv.UserNickname;
                ss.lsSave();
            }).catch(err => {
                jz.alert("查询失败");
                console.log(err);
                ss.loading(0);
            });
        }
    });

    $('input[name="UserNickname"]').val(ss.lsStr("nickname"));
</script>
        </div>
        <a href="javascript:ss.toTop();" class="totop" title="返回顶部">ˆ</a>
</body>
</html>
